#!/usr/bin/perl
#alarms.pl
#require '/usrvol/volume1/ly/diskinfo-lib.pl';
my (@error,@mailconf,@errrd);
@un=`/sbin/tw_cli/tw_cli /c0 show`;
$k=0;
foreach(@un){
	if($_=~/^(u\d+)\s+(\S+)\s+(\S+)\s+/){
		$temp=$1;
		unless($3=~/OK/ || $3=~/VERIFYING/){
			$errrd[$k]=$temp;
			$k++;
		}
	}
}
$j=0;
#print "\@errrd=@errrd\n";
for($i=0;$i<$k;$i++){
	$diskarray=`/sbin/tw_cli/tw_cli /c0/$errrd[$i] show name`;
	$error[$j]=$diskarray;
	$j++;
	$cmd="/sbin/tw_cli/tw_cli"." /c0/$errrd[$i] show 2>/dev/null |";
	open(LSRAID,$cmd);
	while($line=<LSRAID>){
	#	print "\$line=$line\n";	
		if($line=~/^(u\d-*\d*)\s+(\S+)\s+(\S+)\s+(\S*)\s+(\S*)\s+(\S+)/){
	#		print "\$1=$1\n";
			#	print "\$3=$3\n";
			unless ($3 eq 'OK' || $3 eq 'VERIFYING'){
				$error[$j]=$line;
				$j++;
			}
		}
	}
	close(LSRAID);
}	 
#print @error;	
		
#$i=0;
#print @ls;
#foreach(@ls){
#	if ($_=~/DISK/ && $_=~/OK/){
#		$error[$i]=$_;
#		print "$i"."$error[$i]\n";
#		$i++;	
#	}
#}	
if ($i>0){
	open(HH,"/sysvol/etc/alarmconf");
	@alarms=<HH>;
	close(HH);
	print @alarms;
	if($alarms[0]=~/^(checked):hostname=(\S+)/){
		$host=$2;
		`echo "@error"|smbclient -M "$host"`;
	}
	if($alarms[1]=~/^(checked)/){
		open(MA,"/etc/mailconf");
		@mailconf=<MA>;
		close(MA);
		open(MA,">/etc/mailconf");
		for($i=0;$i<5;$i++){
			print MA $mailconf[$i];
		} 
		print MA "\n";
		print MA @error;
		close(MA);
		`/sbin/mailsend /etc/mailconf`;
	}
}

	
